package component.flit.form
{
	import flash.display.MovieClip;
	import flash.events.FocusEvent;
	import flash.text.TextField;
	
	import obecto.core.FLUIComponent;

	[Bindable]
	public class FormItemClass extends FLUIComponent
	{
		public var labelField : TextField;
		public var inputField : TextField;
		public var focusHalo : MovieClip;
		public var errorHalo : MovieClip;
		public var errorBubble : MovieClip;
		
		public var inputText : String = "";
		
		private var labelText : String;
		public function set label(value : String) : void 
		{
			labelText = value;
			if (labelField != null)
			{
				labelField.text = value;
			}
		}
		public function get label() : String
		{
			return labelText;
		}
		
		public function FormItemClass()
		{
			super();
		}
		
		override protected function initialize() : void
		{
			resetParts();
			initializeEventListeners();
		}
		
		private function resetParts() : void 
		{
			inputText = "";
			inputField.text = inputText;
			
			labelField.text = labelText;
			
			focusHalo.visible = false;
			errorHalo.visible = false;
			errorBubble.visible = false
		}
		
		private function initializeEventListeners() : void 
		{
			inputField.addEventListener(Event.CHANGE, handlePasswordInputChange);
			inputField.addEventListener(FocusEvent.FOCUS_IN, handlePasswordFocusIn);
			inputField.addEventListener(FocusEvent.FOCUS_OUT, handlePasswordFocusOut);
		}
		
		private function handlePasswordInputChange(e : Event) : void 
		{
			inputText = inputField.text;
		}
		
		private function handlePasswordFocusIn(e : FocusEvent) : void 
		{
			focusHalo.visible = true;
		}
		
		private function handlePasswordFocusOut(e : FocusEvent) : void 
		{
			focusHalo.visible = false;
		}
		
	}
}